<?php
class NZ_Loader extends CI_Loader 
{
	/**
	 * MY_Loader::l()
     * 
     * Used to translate a text. The text to be translated must be a string between ' and '. As $this->l('Hello world').
     * Things such as $this->l("Hello world"); or $string = "Hello world";$this->l($string); will not work.
	 * 
	 * @param mixed $string the text to be translated.
	 * @param mixed $iso_code
	 * @return
	 */
	public function l ($string, $iso_code = null)
    {
        // Get tu current language
		if (empty($iso_code)) $iso_code = $this->session->flashdata('lang');
        
        // Get the file path relative by application root directory
		$debug = current(debug_backtrace()); 
        $class = basename($debug['file']);
        $path  = str_replace("\\", "/", dirname($debug['file']) );
        
        $times = 5;
        $basePath = substr(dirname(BASEPATH).'/'.APPPATH, 0, strlen(dirname(BASEPATH).'/'.APPPATH)-1);
        while ($path != $basePath && $times > 0) {
            $class = basename($path).'/'.$class;
            $path  = dirname($path);
            $times--;
        }
        
        return TranslateMetier::getTranslation($string, $class, $iso_code);
	}
}

